/*
 *this file is part of nseer erp
 *Copyright (C)2006-2010 Nseer(Beijing) Technology co.LTD/http://www.nseer.com 
 *
 *This program is free software; you can redistribute it and/or
 *modify it under the terms of the GNU General Public License
 *as published by the Free Software Foundation; either
 *version 2 of the License, or (at your option) any later version.
 */
package security.config.task; 
 
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.sql.*;
import javax.servlet.*;
import java.io.* ;
import include.nseer_db.*;

public class taskDetails_register_ok extends HttpServlet{

ServletContext application;
HttpSession session;

public synchronized void service(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{
HttpSession dbSession=request.getSession();
JspFactory _jspxFactory=JspFactory.getDefaultFactory();
PageContext pageContext = _jspxFactory.getPageContext(this,request,response,"",true,8192,true);
ServletContext dbApplication=dbSession.getServletContext();
nseer_db_backup1 security_db = new nseer_db_backup1(dbApplication);
try{
if(security_db.conn((String)dbSession.getAttribute("unit_db_name"))){
String cols_number=request.getParameter("cols_number");
int n=0;
for(int j=1;j<=Integer.parseInt(cols_number);j++){
	String checkbox_name="col"+j;
	String[] cols=request.getParameterValues(checkbox_name);
	if(cols!=null){	
		n++;
	}
}
if(n==0){
response.sendRedirect("security/config/task/taskDetails_register_ok_a.jsp");
}else{
	String sql2="delete from security_task";
	security_db.executeUpdate(sql2) ;
	sql2="update document_second set task_tag='0'";
	security_db.executeUpdate(sql2) ;
	for(int j=1;j<=Integer.parseInt(cols_number);j++){
	String checkbox_name="col"+j;
	String[] cols=request.getParameterValues(checkbox_name);
	if(cols!=null){
	for(int i=0;i<cols.length;i++){
		String sql="select * from document_second where id='"+cols[i]+"'";
		ResultSet rs=security_db.executeQuery(sql) ;
		if(rs.next()){
			String name=rs.getString("main_kind_ID")+"--"+rs.getString("first_kind_ID")+"--"+rs.getString("second_kind_ID");
			String url="../../"+rs.getString("main_kind_name")+"/"+rs.getString("first_kind_name")+"/"+rs.getString("head_file");
			String sql1="insert into security_task(name,url) values('"+name+"','"+url+"')";
			security_db.executeUpdate(sql1) ;
			String sql3="update document_second set task_tag='1' where id='"+cols[i]+"'";
			security_db.executeUpdate(sql3) ;
		}
	}
	}
	}
response.sendRedirect("security/config/task/taskDetails_register_ok_b.jsp");
}
security_db.commit();
security_db.close();
}else{
	response.sendRedirect("error_conn.htm");
}
}catch (Exception ex) {
		ex.printStackTrace();
	}
}
}